package com.yaorange.jxc.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yaorange.jxc.goods.entity.Goods;
import com.yaorange.jxc.goods.entity.GoodsPageRequestResult;



import com.yaorange.jxc.goods.mapper.GoodsMapper1;
import com.yaorange.jxc.goods.service.GoodsService1;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @company: yaorange
 * @author: wu YanZu
 * @version: 1.0
 * @create: 2022-04-28 14:49:35
 */
@Service
public class GoodsServiceImpl1 implements GoodsService1 {
    @Autowired
    private GoodsMapper1 goodsMapper;
    @Override
    public Map<String, Object> selectGoodsListPage(GoodsPageRequestResult result) {
        String goodsName = result.getGoodsName();
        Integer goodsTypeId = result.getGoodsTypeId();
        Integer page = result.getPage();
        Integer rows = result.getRows();
        Integer pageNum = (page-1)*rows;
        List<Goods> goodsList = goodsMapper.selectList(goodsName,goodsTypeId,rows,pageNum);

        HashMap<String, Object> map = new HashMap<>();
        QueryWrapper<Goods> goodsQueryWrapper = new QueryWrapper<>();
        goodsQueryWrapper.eq(!StringUtils.isEmpty(goodsName),"goods_name",goodsName)
                         .or()
                         .eq(goodsTypeId!=0,"goods_type_id",goodsTypeId);

        Integer count = goodsMapper.selectCount(goodsQueryWrapper);
        map.put("total",count);
        map.put("商品列表",goodsList);
        return map;
    }
}
